<?php
class User_model extends CI_Model {

    function __construct()
    {
        // call the Model constructor
        parent::__construct();
		$this->load->database();
    }
    
	function create()
	{
    	$username = $this->input->post('username');
    	$email = $this->input->post('email');
    	$password = $this->input->post('password');
		$password = crypt($password); // if (crypt("mypassword", $password) == $password) {}
		
		$sql = "SELECT COUNT(*) AS c FROM users WHERE username = ?"; // check if username already exists   	
		if ($this->db->query($sql, array($username))->first_row()->c == 0)
		{
			$sql = "INSERT INTO users (username, email, password, date_created) VALUES (?, ?, ?, NOW())";
			$this->db->query($sql, array($username, $email, $password)); 
			return true;
		}
		return false;
	}

	function get_user_by_username($username)
	{
		$sql = "SELECT * FROM users WHERE username = ?"; // check if username already exists   	
		$query = $this->db->query($sql, array($username)); 
		return $query->first_row();
	}

	
}
?>